SetDirectory[NotebookDirectory[]]

Helper methods

<< Bezout.m

BezoutDet = (Subscript[v, i_,j_]) :>xs[[i+1]] ys[[j+1]] - xs[[j+1]] ys[[i +1]];

Define controls points of first curve

a1x = 150; a1y = 150;

a2x = 183.33333333333331;a2y = 216.66666666666663;

a3x = 233.33333333333337;a3y =216.66666666666663;

a4x = 300;a4y =150;

Define control points of second curve

b1x = 100;b1y =200;

b2x = 166.66666666666663; b2y = 133.33333333333337;

b3x = 233.33333333333337; b3y = 133.33333333333337;

b4x = 300;b4y =200;

Calculate Berstein coefficients for first curve

c13x = {a1x, a2x, a3x, a4x}.{-1, 3, -3, 1};

c13y = {a1y, a2y, a3y, a4y}.{-1, 3, -3, 1};

c12x = {a1x, a2x, a3x}.{3, -6, 3};

c12y = {a1y, a2y, a3y}.{3, -6, 3};

c11x = {a1x, a2x}.{-3, 3};

c11y = {a1y, a2y}.{-3, 3};

c10x = a1x;

c10y = a1y;

Calculate Berstein coefficients for second curve

c23x = {b1x, b2x, b3x, b4x}.{-1, 3, -3, 1};

c23y = {b1y, b2y, b3y, b4y}.{-1, 3, -3, 1};

c22x = {b1x, b2x, b3x}.{3, -6, 3};

c22y = {b1y, b2y, b3y}.{3, -6, 3};

c21x = {b1x, b2x}.{-3, 3};

c21y = {b1y, b2y}.{-3, 3};

c20x = b1x;

c20y = b1y;

Define Berstein polynomials

x1 = {c10x, c11x, c12x, c13x}.{1, t, (t^2), (t^3)};

y1 = {c10y, c11y, c12y, c13y}.{1, t, (t^2), (t^3)};

x2 = {c20x, c21x, c22x, c23x}.{1, s, (s^2), (s^3)};

y2 = {c20y, c21y, c22y, c23y}.{1, s, (s^2), (s^3)};

Set axes equal to one another, grouped by ‘t’

xs = CoefficientList[x2 - x1, t]

ys = CoefficientList[y2 - y1, t]

ys = Append[ys, 0]

Find determinant of Bezout matrix

BezoutMatrix[3] //MatrixForm

bd = Collect[Det[BezoutMatrix[3] /. BezoutDet], s];

Plot the resulting polynomial

Plot[bd,{s,0,1}]

Compare to the polynomial I got in Javascript

mybd = -0.011510792319313606 +0.051159076974727116*s - 0.030695446184836248*(s^2)-0.013642420526593955*(s^3)-0.0022737367544323115*(s^4) + 2.067951531382581 × (10^(-17))*(s^5)- 5.877471754111428×(10^(-32))*(s^6);

Plot[mybd, {s, 0, 1}]

Plot[mybd-bd,{s, 0, 1}]

Find roots in ‘s’ for both polynomials

bdroots = Solve[bd == 0, s, Reals]

Solve[mybd == 0, s, Reals]

mybdroots = {{s-> 0.27693915367126465}, {s -> 0.8563182353973389}}

Apply roots

Mathematica’s roots

rx1 = (x2 - x1) /. bdroots[[1]]

rx2 = (x2 - x1) /. bdroots[[2]]

ry1 = (y2 - y1) /. bdroots[[1]]

ry2 = (y2 - y1) /. bdroots[[2]]

My roots from Javascript

mrx1 = (x2 - x1) /. mybdroots[[1]]

mrx2 = (x2 - x1) /. mybdroots[[2]]

mry1 = (y2 - y1) /. mybdroots[[1]]

mry2 = (y2 - y1) /. mybdroots[[2]]

Find roots in ‘t’

Mathematica

Solve[rx1 == 0, t]

Solve[rx2 == 0, t]

Solve[ry1 == 0, t]

Solve[ry2 == 0, t]

Mine

Solve[mrx1 == 0, t]

Solve[mrx2 == 0, t]

Solve[mry1 == 0, t]

Solve[mry2 == 0, t]